﻿using System;
using System.Collections.Generic;
using Slippor.Douban.Radio.Assist;
using Slippor.Douban.Radio.Tracker;

namespace Slippor.Douban.Radio.BaseForm
{
    public class DoubanRadioTrackerService : ITrackerService
    {
        internal DoubanRadioTrackerService()
        {
            Trackers = new Dictionary<String, ITracker>();
        }

        #region ITrackerService Members

        public Dictionary<String, ITracker> Trackers { get; set; }

        public void AddTracker(ITracker tracker)
        {
            Trackers.Add(tracker.Name, tracker);
            if (_lastSong != null)
            {
                tracker.Track(_lastSong);
            }
        }

        public void RemoveTracker(ITracker tracker)
        {
            Trackers.Remove(tracker.Name);
        }

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        private Song _lastSong;
        public void Track(Song song)
        {
            _lastSong = song;
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.Track(song);
            }
        }

        public void TrackUpdate(ICommand command, Song song)
        {
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.TrackUpdate(command, song);
            }
        }

        public void Clear()
        {
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.Clear();
            }
        }

        public void Stop()
        {
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.Stop();
            }
        }

        public void Pause()
        {
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.Pause();
            }
        }

        public void Resume()
        {
            foreach (ITracker tracker in Trackers.Values)
            {
                tracker.Resume();
            }
        }

        #endregion
    }
}